/*
 * Copyright (C) 2020 Agrui
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include "IpcApi.h"
#include "IpcChannelManager.h"
#include "IpcClientManager.h"
#include "IpcAsyncRequest.h"
#include "Signal.h"


#define OBJECT_TO_IPC_HANDLER(x) ((IPC_HANDLER)x)
#define IPC_CLIENT_FROM_IPC_HANDLER(x) ((IpcClient*)x)


void ipcClientHandleRsp(int serviceId, int msgId, int result, void* data, int dataLen, void* userData);

typedef struct {
    int serviceId;
    int subId;
} BindClientDataInfo;

class IpcClient {

public:
    IpcClient(int subId, int serviceId);
    virtual ~IpcClient() ;
    IPC_API_RESULT_T bindSubscription();

    //void handleMgrServiceRsp(int msgId, int result, void* data, int dataLen, void* userData);

protected:
    IPC_API_RESULT_T sendAsyncRequest(int msgId, void* data, int dataLen, IpcAsyncRequest* userData);
    IPC_API_RESULT_T sendSyncRequest(int msgId, void* reqData, int reqDataLen, void* rspData, int rspDataLen);
    IPC_API_RESULT_T sendSyncRequest(int msgId, int serviceId, void* reqData, int reqDataLen, void* rspData, int rspDataLen);

private:
    IpcClientManager*  mClientManager;
    IpcChannelManager* mChannelManager;
    SignalType         mSyncRequestSignal;
    int                mRequestTimeout;
    IpcChannel* mChannel;
    int mSubId;
    int mServiceId;
    int8_t mClientId;
};


